package com.terrynoya.fight.data.parser.sff.v1
{
	import com.terrynoya.fight.data.parser.sff.Bytes;
	import com.terrynoya.fight.data.parser.sff.SFFHeader;
	import com.terrynoya.fight.data.parser.sff.SFFVersion;
	
	import flash.utils.ByteArray;
	import flash.utils.Endian;

	/**
	 * sff fileReader base
	 * parseHeader
	 * parseBody
	 * @author terrynoya
	 */
	public class SFFReaderBase
	{
		public static const HEADER_LENGTH:int = 512;
		
		private var _header:SFFHeader;
		private var _version:SFFVersion;
		private var _compatVer:SFFVersion;
		/**
		 * 
		 * @param bytes
		 */
		public function SFFReaderBase(bytes:ByteArray)
		{
			bytes.endian = Endian.LITTLE_ENDIAN;
			this.parseHeader(bytes);
			this.parseSFF(bytes);
		}
		
		/**
		 * 
		 * @return 
		 */
		protected function get compatVer():SFFVersion
		{
			return _compatVer;
		}

		/**
		 * 
		 * @return 
		 */
		protected function get version():SFFVersion
		{
			return _version;
		}

		/**
		 * 
		 * @return 
		 */
		protected function get header():SFFHeader
		{
			return _header;
		}

		/**
		 * 解析头文件信息 
		 * @param bytes
		 * 
		 */		
		private function parseHeader(bytes:ByteArray):void
		{
			var headerBytes:Bytes=new Bytes(HEADER_LENGTH);
			headerBytes.write(bytes);
			
			this._version=new SFFVersion(headerBytes.data, 12);
			this._compatVer=new SFFVersion(headerBytes.data, 24);
			this._header=new SFFHeader(headerBytes.data, 36);
			
			this.printHeaderInfo();
		}
		
		/**
		 * 
		 * @param bytes
		 */
		protected function parseSFF(bytes:ByteArray):void
		{
			
		}
		
		private function printHeaderInfo():void
		{
			trace("-SFF Version: " + this._version.toString());
			trace("-SFF CompatVer: " + this._compatVer.toString());
			trace("-Number of Images: " + this._header.totalNumSprites);
			trace("-Number of Pallets: " + this._header.totalNumPallets);
			trace("-offsetFirstNode: " + this._header.offsetFirstNode);
			trace("-offsetFirstPalette: " + this._header.offsetFirstPalette);
			trace("-ldataLen: " + this._header.ldataLen);
			trace("-ldataOffset: " + this._header.ldataOffset);
			trace("-tdataLen: " + this._header.tdataLen);
			trace("-tdataOffset: " + this._header.tdataOffset);
		}
	}
}